package com.company.gzcrm.web.controller;

import com.company.gzcrm.model.CRUDResult;
import com.company.gzcrm.model.CourseOrder;
import com.company.gzcrm.model.PageResult;
import com.company.gzcrm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/courseorder")
public class CourseOrderController {

    @Autowired
    ICourseOrderService courseOrderService;

    @RequestMapping("/list")
    public String list(){
        return "courseorder/list";
    }

    @RequestMapping("/add")
    public String add(){
        return "courseorder/add";
    }

    @RequestMapping("/edit")
    public String edit(Model model,String order_id){
        System.out.println("修改订单order_id="+order_id);
        CourseOrder order = courseOrderService.findByOrderId(order_id);
        model.addAttribute("order",order);
        return "courseorder/edit";
    }

    @RequestMapping("/detail")
    public String detail(Model model,String order_id){
        CourseOrder order = courseOrderService.findByOrderId(order_id);
        model.addAttribute("order",order);
        return "courseorder/detail";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public CRUDResult delete(String order_id){
        CRUDResult result = new CRUDResult();
        courseOrderService.deleteByOrderId(order_id);
        return result;
    }

    @RequestMapping("/save")
    @ResponseBody
    public CRUDResult save(CourseOrder order){
        CRUDResult result = new CRUDResult();
        if (order.getOrder_id()==null||order.getOrder_id().length()==0){
            courseOrderService.save(order);
        }else {
            courseOrderService.update(order);
        }
        //{success:1,msg:"}
        System.out.println(order);
        return result;
    }

    @ResponseBody
    @RequestMapping("listJson")
    public PageResult<CourseOrder> listJson(CourseOrder condition ,int page,int limit){
        System.out.println(condition);
        PageResult<CourseOrder> result = courseOrderService.findPageResult(condition,page,limit);
        return result;

    }
}
